/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.siswebvendas.clienteTeste;

import br.com.siswebvendas.cliente.Cliente;
import br.com.siswebvendas.cliente.ClienteRN;
import br.com.siswebvendas.util.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.AfterClass;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.BeforeClass;

/**
 *
 * @author Robson
 */
public class ClienteTeste {

    private static Session session;
    private static Transaction transacao;

    @BeforeClass
    public static void abreConexao() {
        session = HibernateUtil.getSession().getCurrentSession();
        transacao = session.beginTransaction();

    }
    //Fecha conexao com o banco

    @AfterClass
    public static void fechaConexao() {

        try {
            transacao.commit();

        } catch (Throwable e) {
            System.out.println("Problema ao realizar o Commit da Tranzação" + e.getMessage());
        } finally {

            try {
                if (session.isOpen()) {
                    session.close();
                }
            } catch (Exception ex) {

                System.out.println("Ocorreu um erro durante o "
                        + "fechamento da sessão" + ex.getMessage());
            }
        }
    }

    @Test
    public void salvaTeste() {



        Cliente cli1 = new Cliente();
        cli1.setNome("Robson luis");
        cli1.setEndereco("rua dos testes");
        cli1.setReanda(3000f);
        cli1.setCpf("12345678911");

        ClienteRN clienteRN = new ClienteRN();
        clienteRN.salvar(cli1);

        assertEquals(true, true);

    }
}
